package com.bosssoft.rbac.controller;

import com.bosssoft.rbac.domain.SysUser;
import com.bosssoft.rbac.feign.FeignServiceTest;
import com.bosssoft.rbac.feign.JwtToken;
import com.bosssoft.rbac.feign.OAuth2FeignClient;
import com.bosssoft.rbac.model.R;
import com.bosssoft.rbac.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author MaYunFei
 * @ProjectName boss-rbac
 * @Description TODO
 * @time 2022/7/5 21:50
 */
@RestController
@RequestMapping("/test/feign")
@Api(tags = "Feign远程调用测试接口")
public class TestController {

    @Value("${basic.token:Basic cmJhYy1hcGk6cmJhYy1zZWNyZXQ=}")
    private String basicToken ;

    @Autowired
    private OAuth2FeignClient oAuth2FeignClient;

    @Autowired
    private FeignServiceTest feignServiceTest;

    @ApiOperation(value = "查询当前用户")
    @GetMapping("/user/info")
    public R<String> getUserInfo(@RequestHeader("Authorization") String authorization) {
        return R.ok(oAuth2FeignClient.getUserInfo(authorization));
    }

    @ApiOperation(value = "获取权限")
    @PostMapping("/oauth/token")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username" ,value = "账号") ,
            @ApiImplicitParam(name = "password" ,value = "密码") ,
    })
    public R<ResponseEntity<JwtToken>> getToken(@RequestParam("username") String username ,
                              @RequestParam("password") String  password) {
        ResponseEntity<JwtToken> tokenResponseEntity = oAuth2FeignClient.getToken("password", username, password, "admin_type", basicToken);
        return R.ok(tokenResponseEntity);
    }


    @ApiOperation(value = "Feign测试-GET")
    @GetMapping()
    public R<String> getTest(@RequestHeader("Authorization") String authorization) {
        return feignServiceTest.getTest(authorization);
    }

    @ApiOperation(value = "Feign测试-POST")
    @PostMapping()
    public R<String> postTest(@RequestHeader("Authorization") String authorization) {
        return feignServiceTest.postTest(authorization);
    }

    @ApiOperation(value = "Feign测试-PUT")
    @PutMapping()
    public R<String> putTest(@RequestHeader("Authorization") String authorization) {
        return feignServiceTest.putTest(authorization);
    }

}
